<template>
  <div class="header-purchase">
    <div class="inner-header w">
      <div class="logo-box">
        <router-link to="/">
          <img :src="site.logo" :alt="site.site_name" class="logo-header">
        </router-link>
        <div class="subtitle-header">
          <h2>供求频道</h2>
          <h6>商品求购 报价竞标 供求互通</h6>
        </div>
      </div>
      <div class="search-box">
        <div class="input-box" @keydown.enter="handleSearch">
          <input v-model="value" type="text" placeholder="请输入关键字" class="input-inner">
          <button class="input-btn" @click="handleSearch">搜索</button>
        </div>
        <router-link to="/purchase/add" class="add-purchase" target="_blank">
          <span>发布采购单</span>
        </router-link>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'PurchaseHeader',
  data() {
    return {
      value: ''
    }
  },
  mounted() {
    const { keyword } = this.$route.query
    keyword && (this.value = keyword)
  },
  methods: {
    /**
     * 搜索
     */
    handleSearch() {
      let url = '/purchase'
      if (this.value) {
        url += `?keyword=${this.value}`
      }
      this.$router.replace('/')
    }
  }
}
</script>

<style lang="scss" scoped>
@import '../../assets/styles/color';
.header-purchase {
  position: relative;
  z-index: 2;
  width: 100%;
  height: 96px;
  border-bottom: 2px solid $color-main;
  background-color: #FFF;
  .inner-header {
    display: flex;
    justify-content: space-between;
  }
  .logo-box {
    display: flex;
    .logo-header {
      width: 240px;
      height: 68px;
      margin-top: 10px;
    }
    .subtitle-header {
      position: relative;
      margin-left: 20px;
      margin-top: 25px;
      padding-left: 15px;
      &::before {
        content: ' ';
        position: absolute;
        top: 50%;
        left: 0;
        margin-top: -15px;
        width: 1px;
        height: 30px;
        background-color: #dddddd;
        color: #666666;
      }
      h2 {
        font: 24px/30px "microsoft yahei";
      }
      h6 {
        font: 100 12px/20px "microsoft yahei";
      }
    }
  }
  .search-box {
    display: flex;
    margin-top: 24px;
    .input-box {
      .input-inner {
        border: solid #E1E1E1;
        border-width: 1px 0 1px 1px;
        width: 435px;
        height: 40px;
        padding: 7px;
        line-height: 24px;
        box-sizing: border-box;
        color: #555;
      }
      .input-btn {
        width: 100px;
        height: 40px;
        text-align: center;
        color: #ffffff;
        font-weight: bold;
        background-color: $color-main;
        outline: none;
        margin: 0;
        cursor: pointer;
        transition: background-color ease .2s;

        &:hover {
          background-color: darken($color-main, 10);
        }
      }
    }
    .add-purchase {
      width: 120px;
      height: 40px;
      line-height: 40px;
      text-align: center;
      box-sizing: border-box;
      color: #333333;
      border: 1px solid #E1E1E1;
      background-color: #ffffff;
      margin-left: 20px;
      cursor: pointer;
      font-size: 14px;
    }
  }
}
</style>
